var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/ZzdQrCode/index.tsx
var ZzdQrCode_exports = {};
__export(ZzdQrCode_exports, {
  default: () => ZzdQrCode
});
module.exports = __toCommonJS(ZzdQrCode_exports);
var import_icons = require("@ant-design/icons");
var import_react = __toESM(require("react"));
var import_consts = require("./consts");
var import_index = require("./index.less");
function ZzdQrCode({
  mode = "zzd",
  appId,
  redirectUrl,
  onGetCode,
  pure,
  iframeStyle
}) {
  const [timestamp, setTimestamp] = (0, import_react.useState)((/* @__PURE__ */ new Date()).getTime());
  const { appName, appDomain } = (0, import_react.useMemo)(() => {
    return import_consts.BaseConfig[mode];
  }, []);
  (0, import_react.useEffect)(() => {
    const handleLogin = async (event) => {
      var _a;
      if (event.origin === appDomain) {
        if ((_a = event == null ? void 0 : event.data) == null ? void 0 : _a.code) {
          const res = await onGetCode(event.data.code);
          if (!(res == null ? void 0 : res.success))
            setTimestamp((/* @__PURE__ */ new Date()).getTime());
        }
      }
    };
    window.addEventListener("message", handleLogin);
    return () => {
      window.removeEventListener("message", handleLogin);
    };
  }, [appDomain]);
  const iframeSrc = (0, import_react.useMemo)(() => {
    const params = new URLSearchParams();
    params.set("response_type", "code");
    params.set("client_id", appId);
    params.set("redirect_uri", redirectUrl);
    params.set("scope", "get_user_info");
    params.set("authType", "QRCODE");
    params.set("embedMode", "true");
    params.set("timestamp", String(timestamp));
    return `${appDomain}/oauth2/auth.htm?${params.toString()}`;
  }, [appId, redirectUrl, timestamp]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-zzd-qrcode" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "szzj-zzd-qrcode-iframe",
      style: {
        ...iframeStyle ?? {},
        height: (iframeStyle == null ? void 0 : iframeStyle.height) && typeof iframeStyle.height === "number" ? (iframeStyle == null ? void 0 : iframeStyle.height) - 70 : iframeStyle == null ? void 0 : iframeStyle.height
      }
    },
    /* @__PURE__ */ import_react.default.createElement("iframe", { src: iframeSrc, style: iframeStyle })
  ), !pure && /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-zzd-qrcode-tips" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        display: "flex"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-zzd-qrcode-tips-icon" }, /* @__PURE__ */ import_react.default.createElement(import_icons.ScanOutlined, { style: { fontSize: "40px" } })),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-zzd-qrcode-tips-note" }, "打开", /* @__PURE__ */ import_react.default.createElement("span", null, appName, " APP"), /* @__PURE__ */ import_react.default.createElement("br", null), "扫码登录")
  )));
}
